<template>
	<view class="signIn-container">
		<view class="search">
			<uni-search-bar v-model="searchContent" cancelText="搜索" @input="search" @cancel="search" bgColor="#fff"
				placeholder="搜索" />
		</view>
		<view class="nav">
			<view class="navitem" :class="{' navitem-active' : navselect==1 }" @click="navClick(1)">我创建的</view>
			<view class="navitem" :class="{' navitem-active' : navselect==2 }" @click="navClick(2)">我管理的</view>
			<view class="navitem" :class="{' navitem-active' : navselect==3 }" @click="navClick(3)">我签到的</view>
		</view>

		<block v-for="(item,index) in listdata" :key="item.id">
			<!-- v-if="item.type===navselect" -->
			<view class="items">
				<view class="item flex" @click="godetails(item)">
					<view class="cover">
						<image :src="'/static/images/signIn/pic'+item.id%5 +'.jpg'" mode="widthFix"></image>
					</view>
					<view class="item-right">
						<view class="left">
							<view class="title">
								{{item.name}}
							</view>

							<view class="tag" v-if="navselect==3 && item.type==1">
								单次签到
							</view>
							<view class="tag" v-else-if="navselect==3 && item.type==2">
								长期签到
							</view>
							<view class="tag" v-else-if="navselect==3 && item.type==3">
								自由签到
							</view>
							<view class="tag" v-else-if="navselect==3 && item.type==4">
								考勤签到
							</view>
							<view class="tag" v-else-if="item.type==1">
								已签到{{item.sign_num}}人
							</view>
							<view class="tag" v-else>
								今日签到{{item.sign_num}}人
							</view>

						</view>
						<view class="right" @tap.stop="goqrcode(item.code)" v-if="navselect==3">
							<view class="codecover">
								<image src="/static/images/signIn/exportexcel.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="right" @tap.stop="goqrcode2(item.code)" v-else>
							<view class="codecover">
								<image src="/static/images/signIn/qrcode.png" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</block>

		<view class="nonebox" v-if="listdata.length==0">
			<view class="boxcover">
				<image src="/static/images/signIn/empty-box.png" mode=""></image>
			</view>
			<view class="text1">
				空空如也
			</view>
			<view class="text2" v-if="navselect==1">
				点击下方创建新建签到试试吧 
			</view>
			<view class="text2" v-if="navselect==2">
				当前还没有管理的活动哦
			</view>
			<view class="text2" v-if="navselect==3">
				当前还没有签到的活动哦
			</view>
		</view>

		<!-- 底部占位 -->
		<view class="height50upx"></view>
		<!-- 升序降序的按钮 -->
		<view class="floatasc" @click="floatasc">
			<image src="/static/images/signIn/ascdesc.png" mode=""></image>
		</view>


	</view>
</template>

<script>
	import {
		signList
	} from '@/api/activity.js';

	export default {
		data() {
			return {
				navselect: 1,
				listdata: [],
				searchContent: "",
				count: 1
			}
		},
		onShow() {
			this.init()
		},
		onPullDownRefresh() {
			this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh(); //停止下拉刷新动画
			}, 1000);

		},
		onShareAppMessage() {},
		methods: {
			init() {
				signList({
					data: {
						seach_type: this.navselect
					}
				}).then(res => {
					this.listdata = res.data.list
					console.log(this.listdata);
				})
			},

			search() {
				signList({
					data: {
						name: this.searchContent
					}
				}).then(res => {
					this.listdata = res.data.list
					console.log(this.listdata);
					this.$forceUpdate()
				})
			},
			godetails(item) {
				if (this.navselect == 3) {
					uni.navigateTo({
						url: "user-signIn?code=" + item.code + '&navselect=' + this.navselect
					})
				} else {
					uni.navigateTo({
						url: "detail?code=" + item.code + '&navselect=' + this.navselect
					})
				}
			},
			goqrcode2(val) {
				uni.navigateTo({
					url: "signIn-qrcode?code=" + val
				})
			},
			goqrcode(val) {
			
				uni.navigateTo({
					url: "/pages/signIn/export-signIn?code=" + val
				})
			},
			navClick(e) {
				this.navselect = e;
				this.init()
			},
			floatasc() {
				this.count++
				signList({
					data: {
						seach_type: this.navselect,
						order: this.count % 2 == 0 ? 'asc' : 'desc'
					}
				}).then(res => {
					this.listdata = res.data.list
					console.log(this.listdata);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.signIn-container {
		background-color: #f6f6f6;
		min-height: 100vh;

		.search {
			padding: 0 20upx;
		}

		.nav {
			width: 100%;
			background-color: #fff;
			margin-top: 5upxss;
			display: flex;
			padding: 0 30upx;
			font-size: 28upx;

			justify-content: space-around;

			.navitem {
				padding-top: 20upx 0;
				height: 80upx;
				line-height: 80upx;
			}

			.navitem-active {
				border-bottom: 2px solid #1e90ff;
				color: #1e90ff;
			}

		}

		.items {
			margin-top: 10upx;
			padding: 0 10upx;

			.item {
				background-color: #fff;
				border-radius: 10upx;
				padding: 20upx;
				margin-top: 10upx;

				.cover {
					width: 200upx;
					height: 150upx;
					border-radius: 12upx;
					overflow: hidden;
					display: flex;
					align-items: center;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.item-right {
					width: 100%;
					display: flex;
					justify-content: space-between;
					margin-left: 30upx;
					align-items: center;

					.left {
						.title {
							font-size: 32upx;
							margin-bottom: 20upx;
						}

						.tag {
							background-color: #528b8b;
							color: #fff;
							padding: 0 8upx;
							font-size: 22upx;
							width: fit-content;
							text-align: center;
						}
					}

					.right {
						.codecover {
							width: 60upx;
							height: 60upx;
							border-radius: 7upx;
							overflow: hidden;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}
				}
			}

		}

		.nonebox {
			text-align: center;
			padding-top: 100upx;

			.boxcover {

				margin: 0 auto;
				width: 250upx;
				height: 250upx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.text1 {
				margin-top: 20upx;
				font-size: 22upx;
			}

			.text2 {
				margin-top: 20upx;
				font-size: 26upx;
			}
		}

		.floatasc {
			background-color: #d3d7d4;
			border-radius: 100upx;
			position: fixed;
			bottom: 20upx;
			right: 20upx;
			padding: 18upx;
			width: 90upx;
			height: 90upx;

			image {
				width: 100%;
				height: 100%;

			}
		}

		.search-result {
			padding-top: 10px;
			padding-bottom: 20px;
			text-align: center;
		}

		.search-result-text {
			text-align: center;
			font-size: 14px;
			color: #666;
		}

		.example-body {
			/* #ifndef APP-NVUE */
			display: block;
			/* #endif */
			padding: 0px;
		}

		.uni-mt-10 {
			margin-top: 10px;
		}
	}
</style>
